<template>
    <view class="">
        <web-view :src="src" @message="message"></web-view>
    </view>
</template>

<script>
import { mapMutations, mapState, mapGetters } from "vuex"
import { Upload } from "@/pages_supplier/service/api/file.js"
export default {
    computed: {
        ...mapGetters(["getBillMsg"]),
    },
    data() {
        return {
            src: "",
        }
    },
    onLoad() {
        console.log(this.getBillMsg)
        if (this.getBillMsg && (this.getBillMsg.images || this.getBillMsg.remark)) {
            this.src =
                "/pages_supplier/static/file/file.html?images=" +
                this.getBillMsg.images +
                "&remark=" +
                this.getBillMsg.remark
        } else {
            this.src = "/pages_supplier/static/file/file.html"
        }
    },
    mounted() {
        console.log(this.getBillMsg)
    },
    methods: {
        ...mapMutations(["SET_BILLMSG"]),
        update() {
            this.SET_BILLMSG(billMsg)
        },
        message(data) {
            console.log(data)
            // uni.showLoading({
            // 	title: '文件上传中...'
            // })
            let detail = JSON.parse(JSON.stringify(data.detail.data[0]))
            if (detail.changeType == 3) {
                this.easyToast("请选择pdf格式的文件！")
                return
            }
            // 修改备注
            this.getBillMsg.remark = detail.remark || ""
            this.SET_BILLMSG(this.getBillMsg)
            if (detail.base64) {
                // 修改上传文件
                console.log("shancghuan")
                let requestData = {}
                requestData.content = detail.base64.split("base64,")[1]
                console.log(requestData.content)
                requestData.fileType = "pdf"
                uni.showLoading({
                    title: "文件上传中...",
                })
                Upload(requestData).then((res) => {
                    uni.hideLoading()
                    if (res.State == 1) {
                        console.log(res.Data)
                        this.getBillMsg.images = res.Data.Path
                        this.SET_BILLMSG(this.getBillMsg)
                        console.log(this.getBillMsg)
                        this.easyGoBack()
                    } else {
                        this.easyToast(res.Msg)
                    }
                })
            } else {
                this.easyGoBack()
            }
        },
    },
}
</script>

<style></style>
